﻿using System;
using System.Threading;

namespace com.fukefu.update
{
    public partial class UpdateForm : BaseForm
    {
        //单例模式
        private static UpdateForm mf = null;
        private static Object syncObject = new Object();
        //单例模式
        public static UpdateForm GetInstance(UpdateData ud)
        {
            if (mf == null || mf.IsDisposed)
            {
                lock (syncObject)
                {
                    if (mf == null || mf.IsDisposed)
                    {
                        mf = new UpdateForm(ud);
                    }
                }
            }
            return mf;
        }
        private UpdateData d = null;
        private UpdateForm(UpdateData ud)
        {
            InitializeComponent();
            //实例化绑定
            this.d = ud;
            //绑定进度条
            MyProgressBar myprog = new MyProgressBar(picbox);
            d.SetControl += SetControl;
            d._SetMaxNum += myprog.SetMaxNum;
            d._SetNumAdd += myprog.Add;
            //生成标题
            this.Text = d.GetTitle();
        }
        //开始按钮
        private void StartButton_Click(object sender, System.EventArgs e)
        {
            this.listBox1.Items.Clear();
            this.StartButton.Enabled = false;
            new Thread(new ThreadStart(d.Start)).Start();
        }
    }
}
